#include "SandBoxGui.h"

using namespace OgreBites;

SandBoxGui::SandBoxGui(SdkCameraMan *mCameraMan, SdkTrayManager *mTrayMgr)
{
	std::cout << "\n Initializing SandBoxGui";
	this->mCameraMan = mCameraMan;
	this->mTrayMgr = mTrayMgr;

	mLoadingLabel = mTrayMgr->createLabel(OgreBites::TL_CENTER, "TLoading", "", 400);
	mTrayMgr->removeWidgetFromTray(mLoadingLabel);
	mLoadingLabel->hide();

	mStartMenu = new StartMenu(mTrayMgr);
	mStartMenu->hide();
    std::cout << ".";

	mWeatherWindow = new WeatherWindow(mTrayMgr);
	mWeatherWindow->hide();
	std::cout << ".";

	mWaterWindow = new WaterWindow(mTrayMgr);
	mWaterWindow->hide();
	std::cout << ".";

	mEditWindow = new EditWindow(mTrayMgr);
	mEditWindow->hide();
	std::cout << ".";

	mTestWindow = new TestWindow(mTrayMgr);
	mTestWindow->hide();
	std::cout << ".";

	mMainMenu = new SandBoxMainMenu(mTrayMgr);
	mMainMenu->hide();
	std::cout << ".";

	std::cout << "OK\n";
}

//-------------------------------------------------------------------------------------

SandBoxGui::~SandBoxGui(void)
{
}

//-------------------------------------------------------------------------------------
	
void SandBoxGui::setGuimode(bool enabled)
{
		if (enabled)
		{
			mCameraMan->setStyle(CS_MANUAL);
			mTrayMgr->showCursor();
			bGuiMode = true;
		}
		else
		{
			mCameraMan->setStyle(CS_FREELOOK);
			mTrayMgr->hideCursor();
			bGuiMode = false;
		}
}

//-------------------------------------------------------------------------------------
	
void SandBoxGui::toggleGuimode(void)
{
		if (!bGuiMode)
		{
			mCameraMan->setStyle(CS_MANUAL);
			mTrayMgr->showCursor();
			bGuiMode = true;
		}
		else
		{
			mCameraMan->setStyle(CS_FREELOOK);
			mTrayMgr->hideCursor();
			bGuiMode = false;
		}
}
//--------------------------------------------------------------------------------------
void SandBoxGui::showLoadingLabel(Ogre::DisplayString text)
{
	mTrayMgr->moveWidgetToTray(mLoadingLabel,OgreBites::TL_CENTER);
	mLoadingLabel->show();

	mStartMenu->hide();
	mWeatherWindow->hide();
	mWaterWindow->hide();
	mEditWindow->hide();
	mTestWindow->hide();

	mTrayMgr->hideFrameStats();
    mTrayMgr->showBackdrop("SdkTrays/Shade");

	mLoadingLabel->setCaption(text);
}

//--------------------------------------------------------------------------------------

void SandBoxGui::hideLoadingLabel(void)
{
	mTrayMgr->removeWidgetFromTray(mLoadingLabel);
	mLoadingLabel->hide();

	mStartMenu->show();
	switch(mStartMenu->getSelection())
	{
	case StartMenu::Selection_SetWeather:
		mWeatherWindow->show();
	break;

	case StartMenu::Selection_SetWaterParams:
		mWaterWindow->show();
		break;

	case StartMenu::Selection_EditScene:
		mEditWindow->show();
		break;

	case StartMenu::Selection_TestEvents:
		mTestWindow->show();
		break;
	}
	

	mTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
	mTrayMgr->hideBackdrop();
}
//--------------------------------------------------------------------------------------

void SandBoxGui::resetMenus(void)
{
	Ogre::StringVector empty;
	mEditWindow->injectActorNames(empty);
	mEditWindow->injectHolderActorNames(empty);
	mEditWindow->injectEmitterNames(empty);
}

//--------------------------------------------------------------------------------------